<% add_decidim_page_title(t("conference_user_roles.index.conference_admins_title", scope: "decidim.admin")) %>
<div class="card" id="conference_admins">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t("conference_user_roles.index.conference_admins_title", scope: "decidim.admin") %>
      <% if allowed_to? :create, :conference_user_role %>
         <%= link_to t("actions.new_conference_user_role", scope: "decidim.admin"), new_conference_user_role_path(current_conference), class: "button button__sm button__secondary new" %>
      <% end %>
    </h1>
  </div>
  <%= admin_filter_selector %>
  <div class="table-stacked">
    <table class="stack table-list">
      <thead>
        <tr>
          <th><%= sort_link(query, :name,t("models.conference_user_role.fields.name", scope: "decidim.admin"), default_order: :desc) %></th>
          <th><%= sort_link(query, :email, t("models.conference_user_role.fields.email", scope: "decidim.admin"), default_order: :desc) %></th>
          <th><%= sort_link(query, :last_sign_in_at, t("models.user.fields.last_sign_in_at", scope: "decidim.admin"), default_order: :desc) %></th>
          <th><%= sort_link(query, :invitation_accepted_at, t("models.user.fields.invitation_accepted_at", scope: "decidim.admin"), default_order: :desc) %></th>
          <th><%= sort_link(query, :role, t("models.conference_user_role.fields.role", scope: "decidim.admin"), default_order: :desc) %></th>
          <th><%= t("models.conference_user_role.fields.actions", scope: "decidim.admin") %></th>
        </tr>
      </thead>
      <tbody>
        <% filtered_collection.each do |role| %>
          <tr>
            <td data-label="<%= t("models.conference_user_role.fields.actions", scope: "decidim.admin") %>">
              <%= role.user.name %><br>
            </td>
            <td data-label="<%= t("models.conference_user_role.fields.email", scope: "decidim.admin") %>">
              <%= role.user.email %><br>
            </td>
            <td data-label="<%= t("models.user.fields.last_sign_in_at", scope: "decidim.admin") %>">
              <% if role.user.invitation_sent_at %>
                <%= l role.user.invitation_sent_at, format: :short %>
              <% end %>
            </td>
            <td data-label="<%= t("models.user.fields.invitation_accepted_at", scope: "decidim.admin") %>">
              <% if role.user.invitation_accepted_at %>
                <%= l role.user.invitation_accepted_at, format: :short %>
              <% end %>
            </td>
            <td data-label="<%= t("models.conference_user_role.fields.role", scope: "decidim.admin") %>">
              <%= t("#{role.role}", scope: "decidim.admin.models.conference_user_role.roles") %><br>
            </td>
            <td class="table-list__actions" data-label="<%= t("models.conference_user_role.fields.actions", scope: "decidim.admin") %>">
              <button type="button" data-controller="dropdown" data-target="actions-conference-user-role-<%= role.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: role.user.name) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-conference-user-role-<%= role.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to?(:invite, :conference_user_role, user_role: role) && role.user.invited_to_sign_up? %>
                    <li class="dropdown__item">
                      <%= link_to resend_invitation_conference_user_role_path(current_conference, role), method: :post, class: "dropdown__button" do %>
                        <%= icon "refresh-line" %>
                        <%= t("actions.resend_invitation", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <% if allowed_to? :update, :conference_user_role, user_role: role %>
                    <li class="dropdown__item">
                      <%= link_to edit_conference_user_role_path(current_conference, role), class: "dropdown__button" do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <% if allowed_to? :destroy, :conference_user_role, user_role: role %>
                    <li class="dropdown__item">
                      <%= link_to conference_user_role_path(current_conference, role), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button dropdown__button--danger" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
<%= decidim_paginate filtered_collection %>
